package handler

import (
	"log"
	"paper-parser/model"
	"regexp"
)

func ChangePaper() {
	orm := model.Orm()
	err := orm.Where("id > ?", 0).Iterate(new(model.Paper), func(i int, bean interface{}) error {
		p := bean.(*model.Paper)
		//do somthing use i and user
		//p.MinLevel = 1
		//p.Group = "Primary"
		//p.CreatedAt = time.Now()
		//p.UpdatedAt = time.Now()
		//p.TotalScore = 100
		//p.Duration = 120
		//p.PassScore = 60
		//p.Organize = p.Group
		p.Kind = "PastPaper"
		strs := []string{"真题", "公务员考试", "公务员联考", "录用考试", "模拟", "密训", "模考", "专项", "知觉"}
		for _, str := range strs {
			reg, err := regexp.Compile(str)
			if reg.MatchString(p.Name) {
				p.Kind = EnFromCh(str)
			}
			if err != nil {
				log.Fatal(err)
			}
		}
		orm.ID(p.Id).Cols("kind").Update(p)
		return nil
	})
	if err != nil {
		log.Println(err)
	}
}

func EnFromCh(str string) string {
	switch str {
	case "真题":
		return "PastPaper"
	case "公务员考试":
		return "PastPaper"
	case "公务员联考":
		return "PastPaper"
	case "录用考试":
		return "PastPaper"
	case "模拟":
		return "Simulation"
	case "密训":
		return "Simulation"
	case "模考":
		return "Simulation"
	case "专项":
		return "SinglePaper"
	case "知觉":
		return "SinglePaper"
	}
	return ""
}
